import happybase
from util.timeScope import recommend_time, now_time
from txdpy import get_chinese
import jieba

def load_data():
    connection = happybase.Connection('master')
    table = connection.table('news')
    g = table.scan()

    s_list = []
    e_list = []

    end_time, start_time = recommend_time()
    for k, d in g:
        if  start_time < int(str(d[b"info:time"], 'utf-8')) < end_time:
            new_d = {}
            new_d["id"] = str(k, 'utf-8')
            new_d["time"] = str(d[b"info:time"], 'utf-8')
            new_title = [i for i in get_chinese(str(d[b"info:title"], 'utf-8'))]
            new_d["title"] = [i for i in jieba.cut(str(''.join(new_title)))]
            new_d["ifE"] = True
            e_list.append(new_d)

        if now_time(int(str(d[b"info:time"], 'utf-8'))):
            new_d = {}
            new_d["id"] = str(k, 'utf-8')
            new_d["time"] = str(d[b"info:time"], 'utf-8')
            new_title = [i for i in get_chinese(str(d[b"info:title"], 'utf-8'))]
            new_d["title"] = [i for i in jieba.cut(str(''.join(new_title)))]
            new_d["ifE"] = False
            s_list.append(new_d)
    
    return s_list,e_list